package com.ejoysoft.servlet;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Vector;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ejoysoft.wlanyz.system.SignalPara;
import com.ejoysoft.auth.Base64;
import com.ejoysoft.common.DbConnect;
import com.ejoysoft.common.Globa;
import com.ejoysoft.wlanyz.system.SignalPara;
import com.ejoysoft.common.*;


public class ParaServlet extends HttpServlet implements Servlet
{
	private static final long serialVersionUID = 217251451801586160L;
	public ParaServlet()
	{
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException, IOException {	// TODO Auto-generated method stub
		try {
			
		this.execute(req, resp);
		}catch(Exception e) {
			e.printStackTrace();
			throw new IOException(e.getMessage());
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}

	private void execute(HttpServletRequest req, HttpServletResponse resp) throws IOException
	{
		 Globa globa = new Globa();
		  
		
		 //初始化
	    SignalPara obj=new SignalPara(globa);
	    StringBuffer sbReturn = new StringBuffer("");
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		sbReturn.append("[parameter]\r\n");
		Vector<SignalPara> vctObj0= obj.list(" where para_name = 'rays' ",0,0); 
		String temp = (vctObj0==null || vctObj0.size()==0)?"0":String.valueOf(vctObj0.get(0).getParaValue());
		sbReturn.append("rays="+temp+"\r\n");
		//System.out.println("$$$$$$"+pObj0.getParaValue());
		Vector<SignalPara> vctObj1= obj.list(" where para_name = 'cells' ",0,0);
		temp = (vctObj1==null || vctObj1.size()==0)?"0":String.valueOf(vctObj1.get(0).getParaValue());
		sbReturn.append("cells="+temp+"\r\n");
		Vector<SignalPara> vctObj2= obj.list(" where para_name = 'invisible' ",0,0);
		temp = (vctObj2==null || vctObj2.size()==0)?"0":String.valueOf(vctObj2.get(0).getParaValue());
		sbReturn.append("invisible="+temp+"\r\n");
		Vector<SignalPara> vctObj3= obj.list(" where para_name = 'attenuation' ",0,0);
		temp = (vctObj3==null || vctObj3.size()==0)?"0":String.valueOf(vctObj3.get(0).getParaValue());
		sbReturn.append("attenuation="+temp+"\r\n");
		
		
		String strFileName = "ap.ini";//自定义csv文件的文件名
	    resp.setContentType("APPLICATION/*");
	    resp.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1" ));
	    ServletOutputStream output = resp.getOutputStream();
	    output.write(sbReturn.toString().getBytes());
	    globa.closeCon();
 
	}

	

}
